#ifndef _DSWPTZCTRL_H
#define _DSWPTZCTRL_H
#include <libbase/dswconsole_base.h>

typedef struct{
	char nPTZCmd[32];
	int nLen;
	int nDelayMs;
} ST_PTZ_CMD_T, *LPST_PTZ_CMD_T;
typedef std::list<LPST_PTZ_CMD_T> LIST_PTZ_CMD_T, *LPLIST_PTZ_CMD_T;

class CDswPTZCtrl;

typedef struct{
	ST_PTZ_CMD_T nPtzCmd;
	CDswPTZCtrl* pCaller;
	ST_TIMER_PARAM_T nTask;
} ST_PTZ_GOBACK_TASK_T, *LPST_PTZ_GOBACK_TASK_T;

class CDswPTZCtrl : public CDswconsole_base
{
public:
	CDswPTZCtrl(LPST_ENV_T pEnv, LPST_CONSOLE_INFO_T pInfo);
	virtual ~CDswPTZCtrl();
private:
	void SetPTZAction(LPST_APP_PTZ_T pAppPtzAction);
	void PutPTZCmd2Task(char* pCmd, int nDelayms);

	static void cbPtzSendTask(int fd, short events, void* ctx){((CDswPTZCtrl*)ctx)->PtzSendTask(fd, events);};
	void PtzSendTask(int fd, short events);

	static void cbPtzGobackTask(int fd, short events, void* ctx){(((LPST_PTZ_GOBACK_TASK_T)ctx)->pCaller)->PtzGobackTask(fd, events, &(((LPST_PTZ_GOBACK_TASK_T)ctx)->nPtzCmd));};
	void PtzGobackTask(int fd, short events, LPST_PTZ_CMD_T pCmd);
protected:
	virtual int OnMessage(EN_MSG_TYPE nMsgType, void * pParam);
	virtual void OnRead(struct bufferevent *bev){};
private:
	ST_TIMER_PARAM_T m_nPtzTask;
	LIST_PTZ_CMD_T m_nPtzCmdList, m_nEmptyList;
	pthread_mutex_t m_nLock;
	ST_PTZ_GOBACK_TASK_T m_nGobackTask[MAX_CHANNEL_LOCAL];
};

#endif

